<?php

/**
 * @author Kartik
 *
 */
class Buyback_Resource_Offer_Item
{
	/*
	 * ProductGroup Identifier 
	 */
	public $ItemType;
	
	/*
	 * Source Identifier
	 */
	public $Source;
	
	/*
	 * Independant Objects
	 */
	public $Offers;
	
	/*
	 * Objects
	 */
	public $Image;
	public $Dimensions;
	
	/*
	 * Independant Variables
	 */
	public $Metric;
	public $Quantity;
	public $MaxQnty;
	/*
	 * Variables
	 */
	public $Isbn10;
	public $Isbn13;
	public $Title;
	public $Authors = array();
	public $Binding;
	public $Publisher;
	public $PublishYear;
	public $Edition;
	
	public function __construct($source, $object = null, $price = 0, $metric = null, $qnty = 0, $maxqnty = 0)
	{
		$this->Source = $source;
		$this->Offers = new Buyback_Resource_Offer_Price($price, 'USD');
		$this->Quantity = $qnty;
		$this->MaxQnty = $maxqnty;
		$this->Metric = $metric;

		switch(get_class($object))
		{
			case 'Zend_Service_Amazon_Item':
				$this->ItemType = $object->ProductGroup;
				$this->Isbn13 = strlen($object->ISBN)==13?$object->ISBN:null;
				$this->Isbn13 = strlen($object->EAN)==13?$object->EAN:$this->Isbn13;
				
				$this->Isbn10 = Custom_ConvertIsbn::convertIsbn13to10($this->Isbn13);
				$this->Title = $object->Title;
				if(isset($object->Author)){
					$this->Authors = $object->Author;
				}
				$this->Binding = $object->Binding;
				$this->Publisher = $object->Publisher;
				$this->PublishYear = strftime('%y', strtotime($object->PublicationDate)); 
				if(isset($object->Edition)){
					$this->Edition = $object->Edition;
				}
				if(isset($object->SmallImage->Url)){
					$this->Image = $object->SmallImage->Url;
				}
				$this->Dimensions = new Buyback_Resource_Offer_Dimensions($object->Weight, $object->Height, $object->Width, $object->Length);
				break;
			case 'Doctrine_Model_MbsList':
				$this->ItemType = 'Book';
				$this->Isbn13 = $object->isbn13;
				
				$this->Isbn10 = Custom_ConvertIsbn::ConvertIsbn13to10($this->Isbn13);
				$this->Title = $object->title; 
				$this->Authors = $object->authors;
				if(null == $object->binding)
				{	$this->Binding = $object->binding; }
				$this->Publisher = $object->publisher;
				$this->PublishYear = $object->pubYear; 
				$this->Edition = $object->edition;
				$this->Image = null;
				$this->Dimensions = new Buyback_Resource_Offer_Dimensions(200,200,850,1100);
				break;
			case 'Buyback_Resource_Offer_Item':
				if(null != $object){
					$this->ItemType = $object->ItemType;
					$this->Isbn13 = $object->Isbn13;
					
					$this->Isbn10 = $object->Isbn10;
					$this->Title = $object->Title;
					$this->Authors = $object->Authors;
					$this->Binding = $object->Binding;
					$this->Publisher = $object->Publisher;
					$this->PublishYear = $object->PublishYear; 
					$this->Edition = $object->Edition;
					
					$this->Image = $object->Image;
					$this->Dimensions = $object->Dimensions;
				}
			default: 
				return null;	
		}	
		
		return $this;
	}
}